﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Goods_List.aspx.cs" Inherits="ncp.Web.cms.Goods_List" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../themes/icon.css" />
	<script type="text/javascript" src="../../js/jquery-1.7.1.min.js"></script>
	<script type="text/javascript" src="../../js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../js/common.js"></script>
</head>
<body style="margin:0; padding:0px;">
    <form id="form1" runat="server">
        <div class="toolbar" style="background-color:#efefef">
            <a id="divA" href="#" class="easyui-linkbutton" plain="true" iconCls="icon-ok" onclick="onReleaseGoods();">发布</a>
        </div>
        <div id="divright">    
        </div>
	</form>
</body>
</html>
<script type="text/javascript">
    var rowIndex_List = "0";
    $(function() {
        initDatagrid();
        LoadGoodsInfo();
    });


    //初始化表格
    function initDatagrid() {
        $('#divright').datagrid({
            nowrap: true,
            striped: true,
            singleSelect: false,
            sortName: 'GC_Id',
            sortOrder: 'asc',
            remoteSort: false,
            idField: 'GC_Id',
            pagination: false,
            rownumbers: true,
            columns: [[
					{ field: 'GC_Id', title: '商品类别ID', hidden: 'true', width: 80 },
					{ field: 'GC_Name', title: '商品类别名称', sortable: 'true', width: 80, align: 'center' },
					{ field: 'GC_Flag', title: '发布位置', sortable: 'true', width: 80, align: 'center',
					    formatter: function(value, rec, rowIndex) {
					        var strReturn = "";
					        if (value == null) return strReturn; ;
					        if (value.indexOf('h') >= 0) {
					            strReturn += "[首页] ";
					            rowIndex_List += "," + rowIndex;
					        }
					        if (value.indexOf('c') >= 0) {
					            strReturn += "[推荐] ";
					            rowIndex_List += "," + rowIndex;
					        }
					        return strReturn;
					    }
					}
				]]
        });
    }

    //装载商品信息视图
    function LoadGoodsInfo() {
        var GC_Id = QueryString("u");
        if (GC_Id == "1")
            $('#divA').linkbutton({text:'发布农品'});
        else if (GC_Id == "2")
            $('#divA').linkbutton({text:'发布农资'});
        else
            $('#divA').linkbutton({ text: '发布资讯' });
        var data = eval(ncp.Web.cms.Goods_List.BindTable(GC_Id).value);
        $('#divright').datagrid('loadData', data);
        var n = rowIndex_List.split(",");
        for (var i = 1; i < n.length; i++) {
            $('#divright').datagrid('selectRow', n[i]);
        }
    }

    //发布商品
    function onReleaseGoods() {
        if (confirm("您确定要发布吗？")) {
            var response = ncp.Web.cms.Goods_List.ReleaseGoods(QueryString("u"));
            if (response.value != null) {
                var jsonOBJ = eval(response.value)[0];
                if (jsonOBJ.isreload) {
                    LoadGoodsInfo();
                }
                alert(jsonOBJ.msg);
            }
        }
        return false;
    }
    
    //选择多条商品记录
    function getSelections() {
        var ids = "";
        var rows = $('#divright').datagrid('getSelections');
        for (var i = 0; i < rows.length; i++) {
            ids +=","+rows[i].GC_Id;
        }
        return "0"+ids;
    }
    
</script>
